import Page
from Page import Yomi
from Base.Base import Base
from selenium.webdriver.common.by import By


class YomiPassagePage(Base):
    """
    语音训练一段话页

    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 左侧的返回键
        self.passage_back_btn = (By.XPATH, Yomi.RESOURCE_ID_Assistant.format('ivBack'))

        # 左侧的home键
        self.passage_home_btn = (By.XPATH, Yomi.RESOURCE_ID_Assistant.format('ivHome'))

        # 一段话标题
        self.passage_title_text = (By.XPATH, Yomi.passage_title_text.format(""))

        # 语音按钮
        self.passage_voice_btn = (By.XPATH, Yomi.RESOURCE_ID.format("rl_mic"))

        # 语音输入框
        self.passage_select_input = (By.XPATH, Yomi.RESOURCE_ID.format("et_voice"))

        # 文字个数
        self.passage_text_number_text = (By.XPATH, Yomi.RESOURCE_ID.format("tv_count"))

        # 确认按钮
        self.passage_sure_btn = (By.XPATH, Yomi.RESOURCE_ID.format("btn_sure"))

    def click_back(self):
        """
        点击左侧的back键

        :return:None
        """
        self.click_element(self.passage_back_btn)

    def click_home(self):
        """
        点击左侧的home键

        :return:None
        """
        self.click_element(self.passage_home_btn)

    def get_title(self, index):
        """
        获取一段话标题

        :return:获取元素
        """
        self.passage_title_text = (By.XPATH, Yomi.passage_title_text.format(index))
        return self.find_element_o(self.passage_title_text)

    def click_voice(self):
        """
        点击语音输入键

        :return:None
        """
        self.click_element(self.passage_voice_btn)

    def input_select(self, index):
        """
        点击语音输入框

        :return:None
        """
        self.input_text(self.passage_select_input, index)

    def get_text_number(self):
        """
        获取文字个数

        :return:获取元素
        """
        return self.find_element_o(self.passage_text_number_text)

    def get_sure(self):
        """
        获取确认按钮属性

        :return:获取元素
        """
        return self.find_element_o(self.passage_sure_btn)

    def click_sure(self):
        """
        点击确认按钮

        :return:None
        """
        self.click_element(self.passage_sure_btn)

    def is_display_yomi_new(self):
        """
        查看是否新闻页

        :return:
        """
        return self.is_display(self.passage_voice_btn)
